package xyz.robinbingo.pfboot.util;

import org.omnifaces.util.Messages;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

/**
 * FaceUtils
 *
 * @author Robin
 * @date 2018/10/18 19:35
 **/
public class FaceUtils {

    public static void addMessage(String message) {
        addMessage(message, null);
    }

    public static void addMessage(String message, FacesMessage.Severity severity) {

        FacesMessage facesMessage = Messages.create("").detail(message).get();
        if (severity != null && severity != FacesMessage.SEVERITY_INFO) {
            facesMessage.setSeverity(severity);
        }
        Messages.add(null, facesMessage);
    }

    public static HttpServletRequest getRequest() {
        return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    }

    public static String getParam(String name) {
        return getRequest().getParameter(name);
    }
}
